package com.fitness.servlet;

import com.fitness.dao.ReservationDAO;
import com.fitness.entity.Reservation;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/ReservationQueryServlet")
public class ReservationQueryServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String action = request.getParameter("action");
        if ("list".equals(action)) {
            ReservationDAO reservationDAO = new ReservationDAO();
            List<Reservation> reservationList = reservationDAO.getAllReservations();
            request.setAttribute("reservationList", reservationList);
            request.getRequestDispatcher("/WEB-INF/views/admin/reservationList.jsp").forward(request, response);
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}